<template lang="pug">
  div
    s-table(
      ref="table"
      :column="tableObj.column"
      :filterProps="{items: filterItems}"
      :queryFn="tableObj.getList"
      title="执法视频库"
      )
      .table-operator(slot="table-operator")
        el-button(size="small" type="success" @click="addHandle()") 上传
      template(slot="action" slot-scope="text, scope")
        el-link(type="success" :underline="false" v-action:info) 下载
        el-link(type="primary" :underline="false" @click="addHandle(scope.lawVideoId)" v-action:info) 修改
        el-popconfirm(title="确定删除该任务吗？" v-if="scope.taskStas === '0'" @confirm="deleteHandle(scope.lawVideoId)" @onConfirm="deleteHandle(scope.lawVideoId)")
          el-link.ml5(type="danger" :underline="false" slot="reference") 删除
    law-import-modal(:visible.sync="importObj.visible" :id="importObj.id" @getList="refreshTable")
</template>
<script>
import { STable } from '@/components'
import { lawVideoList, lawVideoDelete } from '@/api/libary'
import LawImportModal from './LawImportModal'

const column = [
  {
    prop: 'personId',
    label: '记录ID',
    align: 'center'
  },
  {
    prop: 'name',
    label: '拍摄日期',
    align: 'center'
  },
  {
    prop: 'idcard',
    label: '上传时间',
    align: 'center'
  },
  {
    prop: 'sicard',
    label: '执法地点'
  },
  {
    prop: 'addTimeString',
    label: '备注信息'
  },
  {
    prop: 'action',
    label: '操作',
    width: '156',
    align: 'center'
  }
]

export default {
  components: {
    STable,
    LawImportModal
  },
  computed: {
    filterItems () {
      return [
        {
          key: 'keywords',
          label: '关键信息'
        },
        {
          key: 'addDate',
          label: '拍摄日期',
          type: 'daterange'
        },
        {
          key: 'upDate',
          label: '上传日期',
          type: 'daterange'
        }
      ]
    }
  },
  data () {
    return {
      tableObj: {
        column,
        getList: lawVideoList
      },
      importObj: {
        id: '',
        visible: false
      }
    }
  },
  methods: {
    // 刷新表格
    refreshTable (flag = false) {
      this.$refs.table.refresh(flag)
    },
    addHandle (id = '') {
      this.importObj = {
        id,
        visible: true
      }
    },
    // 删除
    deleteHandle (id) {
      lawVideoDelete(id).then(() => {
        this.$message.success('删除成功')
        this.refreshTable()
      })
    }
  }
}
</script>
